package org.tinygroup.trans.xstream.springtrans;

import org.springframework.messaging.Message;
import org.tinygroup.trans.xstream.util.XStreamConvertUtil;
import org.tinygroup.xstream.XStreamFactory;

import com.thoughtworks.xstream.XStream;

public class XStreamTransformDefault {
	private String xstreamPackageName;

	public String getXstreamPackageName() {
		return xstreamPackageName;
	}

	public void setXstreamPackageName(String xstreamPackageName) {
		this.xstreamPackageName = xstreamPackageName;
	}

	/**
	 * xml转对象，采用xstream的方式
	 * 
	 * @param inMessage
	 * @return
	 */
	public Object transfor2Object(Message<?> inMessage) {
		XStream xStream = XStreamFactory.getXStream(xstreamPackageName);
		return XStreamConvertUtil.xml2Object(xStream,
				(String) inMessage.getPayload());
	}

	/**
	 * 对象转xml，采用xstream的方式
	 * 
	 * @param inMessage
	 * @return
	 */
	public String transfor2Xml(Message<?> inMessage) {
		XStream xStream = XStreamFactory.getXStream(xstreamPackageName);
		return XStreamConvertUtil.object2Xml(xStream, inMessage.getPayload());
	}

}
